package com.xxc.domain.strategy.service.rule.tree.factory;

import com.xxc.domain.strategy.model.valobj.RuleLogicCheckTypeVO;
import com.xxc.domain.strategy.model.valobj.RuleTreeVO;
import com.xxc.domain.strategy.service.rule.tree.ILogicTreeNode;
import com.xxc.domain.strategy.service.rule.tree.factory.engine.IDecisionTreeEngine;
import com.xxc.domain.strategy.service.rule.tree.factory.engine.impl.DecisionTreeEngine;
import lombok.*;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @Author: xxc
 * @Description: 规则树工厂
 * @Date: 2025/1/29 19:45
 * @Version: 1.0
 */

@Service
public class DefaultTreeFactory {

    private final Map<String, ILogicTreeNode> logicTreeNodeGroup;

    public DefaultTreeFactory(Map<String, ILogicTreeNode> logicTreeNodeGroup) {
        this.logicTreeNodeGroup = logicTreeNodeGroup;
    }

    public IDecisionTreeEngine openLogicTree(RuleTreeVO ruleTreeVO) {
        return new DecisionTreeEngine(logicTreeNodeGroup, ruleTreeVO);
    }

    /**
     * 决策树个动作实现
     */
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class TreeActionEntity{
        private RuleLogicCheckTypeVO ruleLogicCheckType;
        private StrategyAwardVO strategyAwardVO;
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class StrategyAwardVO {
        /** 抽奖奖品ID - 内部流转使用 */
        private Integer awardId;
        /** 抽奖奖品规则 */
        private String awardRuleValue;
    }

    @Getter
    @AllArgsConstructor
    public enum LogicModel {

        RULE_LOCK("rule_lock", "次数锁"),
        RULE_STOCK("rule_stock", "库存判断"),
        RULE_LUCK_AWARD("rule_luck_award", "兜底奖励"),
        ;

        private final String code;
        private final String info;

    }
}
